import axios from "axios";


const instanceEcommerce = axios.create({
    baseURL: 'http://127.0.0.1:8888/api/private/v1/',
    timeout: 3000
})

function request(req) {
    if (req.url != 'login') {
        instanceEcommerce.interceptors.request.use(config => {
            config.headers.Authorization = window.sessionStorage.getItem('token');
            console.log(config);
            return config;
        });
    }
    instanceEcommerce.interceptors.response.use(res => {
        console.log(res);
        
        if(res.config) {
            return res.data;
        }else {
            return res;
        }
    });
    return new Promise((resolve, reject) => {
        instanceEcommerce(req).then(data => {
            resolve(data)
        }).catch(err => {
            reject(err);
        })
    })
}

export default request;